package com.appkubes.mall.admin.application.customer.customer.controller;

import com.appkubes.cloud.config.params.paramValid.ParamValid;
import com.appkubes.common.Response;
import com.appkubes.mall.admin.application.customer.customer.entity.vo.*;
import com.appkubes.mall.admin.application.customer.customer.entity.dto.CustomerInfoDTO;
import com.appkubes.mall.admin.application.customer.customer.service.CustomerService;
import com.appkubes.mall.core.controller.BaseMallCustomerController;
import com.appkubes.mall.core.entity.MallAdmin;
import com.appkubes.mall.core.entity.MallAdminBinding;
import com.appkubes.mall.core.entity.MallCustomer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Rongjie
 * @Date: 2020/3/4
 * @Description:
 */
@Api(tags = "渠道用户表")
@RestController
@RequestMapping("/customer")
public class CustomerController extends BaseMallCustomerController {

    @Autowired
    CustomerService customerService;

    @GetMapping("/userInfo")
    @ApiOperation("获取用户信息")
    public Response userInfo(@ParamValid CustomerKeyVO customerKeyVO) {
        MallCustomer customer = new MallCustomer();
        BeanUtils.copyProperties(customer,customerKeyVO);
        customer = customerService.getOneByEntity(customer);
        return Response.success(customer);
    }

    @PostMapping("/modifyUserInfo")
    @ApiOperation("修改用户信息")
    public Response modifyUserInfo(@ParamValid ModifyCustomerVO modifyCustomerVO) {
        MallCustomer customer = new MallCustomer();
        BeanUtils.copyProperties(modifyCustomerVO,customer);

        Boolean flag = customerService.saveOrUpdate(customer);
        return Response.success(flag);
    }

    @ApiOperation("手机号码登陆")
    @PostMapping("/loginByTel")
    public Response loginByTel(@ParamValid LoginByTelVO loginByTel){
        MallAdminBinding adminBinding = customerService.loginByTel(loginByTel);
        return Response.success(adminBinding);
    }

    @ApiOperation("手机号注册")
    @PostMapping("/registerByTel")
    public Response registerByTel(@ParamValid RegisterByTelVO registerByTel){
        MallAdminBinding adminBinding = customerService.registerByTel(registerByTel);
        return Response.success(adminBinding);
    }
}
